package cn.itcast.controller;

import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/sessions")
public class SessionController {

    @GetMapping("/s1")
    public void setData(String username, HttpSession session){
        log.warn("session的编号是:" + session.getId());
        session.setAttribute("username",username);
    }

    @GetMapping("/s2")
    public void getData(HttpSession session){
        log.warn("session的编号是:" + session.getId());
        Object username = session.getAttribute("username");
        System.out.println(username);

    }
}
